package com.qtyx.nms.util

import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager

object Tools {

    /**
     * 获取本地的版本号
     * @return
     */
    fun getVersionName(context: Context): String {
        var version = "0"
        val manager = context.packageManager
        val info: PackageInfo
        try {
            info = manager.getPackageInfo(context.packageName, 0)
            version = info.versionName
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
        return version
    }

    /**
     * 获取本地的版本Code
     * @return
     */
    fun getVersionCode(context: Context): Int {
        var version = 0
        val manager = context.packageManager
        val info: PackageInfo
        try {
            info = manager.getPackageInfo(context.packageName, 0)
            version = info.versionCode
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
        return version
    }


}